import Vue from 'vue'
import Vuex from 'vuex'
import {LoginApi} from '../request/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:''
  },
  mutations: {
    SaveToken(state,payload){
      state.token=payload
    }
  },
  actions: {
    // 登录的方法
    login({state,commit},payload){
      LoginApi(payload).then(res=>{
        if(res.errno===0){
         commit('SaveToken',res.data.token)
      state.token=payload
         localStorage.setItem('token',res.data.token)
        }
      })
    }
  },
  modules: {
  }
})
